/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.crystalrange.documents.service.impl;

import com.googlecode.genericdao.search.Search;
import com.googlecode.genericdao.search.SearchResult;
import java.util.Date;
import java.util.List;
import org.crystalrange.documents.dao.DocumentReferenceTypeDao;
import org.crystalrange.documents.model.DocumentReferenceType;
import org.crystalrange.documents.service.DocumentReferenceTypeService;
import org.crystalrange.model.User;
import org.crystalrange.service.UserService;

/**
 *
 * @author Krzysiek
 */
public class DocumentReferenceTypeServiceImpl implements DocumentReferenceTypeService {

    private DocumentReferenceTypeDao documentReferenceTypeDao;
    private UserService userService;

    public DocumentReferenceTypeDao getDocumentReferenceTypeDao() {
        return documentReferenceTypeDao;
    }

    public void setDocumentReferenceTypeDao(DocumentReferenceTypeDao documentReferenceTypeDao) {
        this.documentReferenceTypeDao = documentReferenceTypeDao;
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }
    
    public DocumentReferenceType create(String username) {
        User currentUser = this.userService.findByUsername(username);   
        
        DocumentReferenceType documentReferenceType = new DocumentReferenceType();
        documentReferenceType.setCreatedBy(currentUser);
        documentReferenceType.setCreatedDate(new Date());
        
        return documentReferenceType;
    }

    public boolean save(DocumentReferenceType documentReferenceType) {
        return this.documentReferenceTypeDao.save(documentReferenceType);
    }

    public boolean remove(DocumentReferenceType documentReferenceType) {
        return this.documentReferenceTypeDao.remove(documentReferenceType);
    }

    public DocumentReferenceType find(Long id) {
        return this.documentReferenceTypeDao.find(id);
    }

    public List<DocumentReferenceType> findAll() {
        return this.documentReferenceTypeDao.findAll();
    }

    public SearchResult<DocumentReferenceType> searchAndCount(Search search) {
        return this.documentReferenceTypeDao.searchAndCount(search);
    }

    public List<DocumentReferenceType> search(Search search) {
        return this.documentReferenceTypeDao.search(search);
    }

    public DocumentReferenceType searchUnique(Search search) {
        return this.documentReferenceTypeDao.searchUnique(search);
    }
    
}
